package zyz.framework.service;

import zyz.framework.dao.dml.DmlItem;
import zyz.framework.dao.query.QueryItem;
import zyz.framework.entity.Page;
import zyz.framework.exception.ServiceException;

import java.util.List;
import java.util.Map;

public interface BaseService {
    /**
     * 插入
     *
     * @param dmlItem
     * @return 返回主键
     * @throws Exception
     */
    public Long insert(DmlItem dmlItem) throws ServiceException;

    /**
     * 插入(主键为id)
     *
     * @param object
     * @return
     * @throws Exception
     */
    public Long insert(Object object) throws ServiceException;

    /**
     * 插入(主键不为id)
     *
     * @param object
     * @return
     * @throws ServiceException
     */
    public Long insert(String pkColumn, Object object) throws ServiceException;

    /**
     * 插入(主键不为id)
     *
     * @param obj Map
     * @return
     * @throws ServiceException
     */
    public Long insert(String pkColumn, Map obj, Class<?> clazz) throws ServiceException;


    /**
     * 更新
     *
     * @param dmlItem
     * @return 返回更新的记录数
     * @throws ServiceException
     */
    public Integer update(DmlItem dmlItem) throws ServiceException;

    /**
     * 更新
     *
     * @return
     * @throws ServiceException
     */
    public Integer updateById(Object object) throws ServiceException;

    /**
     * 更新
     *
     * @return
     * @throws ServiceException
     */
    public Integer updateByPk(String pkColumn, Map obj, Class<?> clazz) throws ServiceException;


    /**
     * 更新
     *
     * @param object
     * @param updateEmpty 是否更新null
     * @return
     * @throws ServiceException
     */
    public Integer updateById(Object object, boolean updateEmpty) throws ServiceException;

    /**
     * 更新
     *
     * @param pkColumn
     * @param object
     * @return
     * @throws ServiceException
     */
    public Integer updateById(String pkColumn, Object object) throws ServiceException;


    /**
     * 更新
     *
     * @param pkColumn
     * @param object
     * @return
     * @throws ServiceException
     */
    public Integer updateById(String pkColumn, Object object, boolean updateEmpty) throws ServiceException;


    /**
     * 删除
     *
     * @param dmlItem
     * @return 返回删除记录数
     * @throws ServiceException
     */
    public Integer delete(DmlItem dmlItem) throws ServiceException;

    /**
     * 根据主键(id)删除数据
     *
     * @param id       要删除的记录ID
     * @return
     * @throws ServiceException
     */
    public Integer deleteById(String id,Class<?> clazz) throws ServiceException;

    /**
     * 根据主键删除数据(主键字段不是id，要另外指定如：menu_id)
     *
     * @param pkColumn 数据库字段名
     * @param id       主键值
     * @return
     * @throws ServiceException
     */
    public Integer deleteById(String pkColumn, String id, Class<?> clazz) throws ServiceException;

    /**
     * 查询单条记录(返回Map)
     *
     * @param queryItem
     * @return
     * @throws ServiceException
     */
    public Map<String, Object> getOne(QueryItem queryItem) throws ServiceException;

    /**
     * 查询单条记录(返回Entity)
     *
     * @param queryItem
     * @param clazz
     * @return
     * @throws ServiceException
     */
    public <T> T getOne(QueryItem queryItem, Class<T> clazz) throws ServiceException;

    /**
     * 查询多条记录
     * 1、如果queryItem.page和queryItem.limit都不为空，返回满足条件的第page页的记录(Page)
     * 2、如果queryItem.limit为空，queryItem.page不为空，limit取默认值20，返回满足条件的第page页的记录(Page)
     * 3、如果queryItem.page为空，queryItem.limit不为空，返回满足条件的前n条记录(List<Map<String, Object>>)
     * 4、如果queryItem.page和queryItem.limit都为空，返回满足条件的所有记录(List<Map<String, Object>>)
     *
     * @param queryItem
     * @return
     * @throws ServiceException
     */
    public Object getList(QueryItem queryItem) throws ServiceException;

    /**
     * 查询多条记录(绑定entity)
     *
     * @param queryItem
     * @param clazz
     * @return
     * @throws ServiceException
     */
    public <T> List<T> getList(QueryItem queryItem, Class<T> clazz) throws ServiceException;

    /**
     * 查询多条记录(绑定entity)
     *
     * @param queryItem
     * @param clazz
     * @return
     * @throws ServiceException
     */
    public <T> Page<T> getPage(QueryItem queryItem, Class<T> clazz) throws ServiceException;

    /**
     * 统计满足条件的记录数
     *
     * @param queryItem
     * @return
     * @throws ServiceException
     */
    public Integer getListCount(QueryItem queryItem) throws ServiceException;
}